/**
 * Copyright(c) 2010 Ceno Techonologies Co., Ltd.
 *
 * History:
 *   15-5-18 下午6:06 Created by lyyang
 */
package com.jade.bss.web.resolver;

import java.io.Serializable;
import com.jade.bss.base.customer.Customer;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

/**
 * 用户封装类,用于resolver
 *
 * @author <a href="mailto:lyyang@ceno.cn">lyyang</a>
 * @version 1.0 15-5-18 下午6:06
 */
public class CustomerCapsule implements Serializable
{
    private Customer customer;

    public CustomerCapsule(){

    }

    public CustomerCapsule(Customer customer){
        this.customer = customer;
    }

    public void setCustomer(Customer customer)
    {
        this.customer = customer;
    }

    public Customer unwrap(){
        if (customer==null){
            Subject subject = SecurityUtils.getSubject();
            if (subject.getPrincipal() instanceof  Customer){
                customer = (Customer)subject.getPrincipal();
            }
        }
        return customer;
    }
}
